using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using OpenMTS.Properties;
using NAVA.MTSLibrary;

namespace OpenMTS
{
    public partial class EvaluatorDlg : Form
    {

        private MessageTester mt = null;

        public EvaluatorDlg()
        {            
            mt = MessageTester.MessageTesterFactory();

            InitializeComponent();
        }

        private void btnInputFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Xml files (*.xml)|*.xml|All files (*.*)|*.*";
            DialogResult result = dlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                txtInputMessage.Text = dlg.FileName;
            }
        }

        private void EvaluatorDlg_Load(object sender, EventArgs e)
        {
            if (Settings.Default.InputFile != null)
                this.txtInputMessage.Text = Settings.Default.InputFile;

        }

        private void EvaluatorDlg_FormClosing(object sender, FormClosingEventArgs e)
        {
            Settings.Default.InputFile = this.txtInputMessage.Text;            
            Settings.Default.Save();
        }

       

        private void commandPrompt1_Command(object sender, CommandPrompt.CommandEventArgs e)
        {

            try
            {
                XmlDocument xInputMessage = new XmlDocument();
                xInputMessage.Load(this.txtInputMessage.Text);

                e.Message = mt.evaluateExpression(xInputMessage.OuterXml, e.Command);
            }
            catch (Exception ex)
            {
                e.Message = ex.Message;
            }

           
        }

        private void EvaluatorDlg_Resize(object sender, EventArgs e)
        {

        }
    }
}